package dashboard;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ForgotPasswordServlet extends HttpServlet {

	private ForgotPasswordController FPC;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		FPC = new ForgotPasswordController();
		String toCheck = req.getParameter("FPfield");
		
		User user = FPC.getUser(toCheck);
		
		if(user != null)
		{
			
			Mail.getInstance().sendForgotPasswordMsg(user.getEmail(), user.getName(), user.getPassword());
			resp.sendRedirect("dashboard.jsp?I=mail");
		}
		else{
			resp.sendRedirect("forgotpassword.jsp?FP=false");
		}

	}
}
